package com.ddf.springdata.jpa.dao.impl;

import com.ddf.springdata.jpa.dao.UserDao;
import com.ddf.springdata.jpa.entity.User;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * @author DDf on 2018/9/28
 * 如果Repository接口有不满足的地方，可以自定义接口与实现，然后让Repository接口继承自定义的接口接口，继续使用Repository来操作
 * @PersistenceContext 可以将JPA原生对象注入进来
 */
@Repository
public class UserRepositoryImpl implements UserDao {
    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public User getUserById(Integer id) {
        return entityManager.find(User.class, id);
    }
}
